package com.o2opuzi.pub.controller

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.google.code.yanf4j.core.Session;
import com.o2opuzi.pub.service.UserService;

@RestController
@RequestMapping("/admin")
class AdminIndexController {
	
	@Autowired
	private UserService userService;
	
	@GetMapping("/user/info")
	def userInfo(HttpSession session){
		def admin = session.getAttribute("adminLogin");
		def user = admin["user"];
		return [
			code:1
		];
	}
	
	
	@PostMapping("/user/info")
	def userInfo(@RequestBody Map user){
		return [:];
	}
	
	
	/**
	 * 用户的登录记录
	 * @auther Y.hj
	 * @param page
	 * @param size
	 * @param session
	 * @return
	 */
	@GetMapping("/user/loginlogs")
	def userLoginLogs(Integer page,Integer size,HttpSession session){
		def admin = session.getAttribute("adminLogin");
		def user = admin["user"];
		return [
			code:1,
			data:userService.getUserLoginLogs(user["id"], page, size)
		];
	}
	
	/**
	 * 用户的操作记录
	 * @auther Y.hj
	 * @param page
	 * @param size
	 * @param session
	 * @return
	 */
	@GetMapping("/user/optlogs")
	def userOptLogs(Integer page,Integer size,HttpSession session){
		def admin = session.getAttribute("adminLogin");
		def user = admin["user"];
		return [
			code:1,
			data:userService.getUserOptLogs(user["id"], page, size)
		];
	}
	
}
